<?php

class LoginController extends Zend_Controller_Action
{

    public function preDispatch()
    {
    }
    
    public function indexAction()
    {
        $login = new Application_Form_LoginForm(array(
            'action' => '/login/index',
            'method' => 'post',
        ));
        $this->view->form = $login;
        if($this->getRequest()->isPost())
        {
        	if($login->isValid($_POST)){
        		$adapter = new Admin_Auth_Adapter($this->_getParam('username'), $this->_getParam('password'));
        		$result = Zend_Auth::getInstance()->authenticate($adapter);
        		
        		if(Zend_Auth::getInstance()->hasIdentity())
        		{
        			//var_dump(Zend_Auth::getInstance()->getIdentity());
        			$this->_forward('processing');
        		}
        		else
        		{
        			$this->view->message = implode(' ', $result->getMessages());
        		}
        	}
        }
        
    }
    
    public function processingAction(){
    	
    }
    
    public function logoutAction()
    {
    	Zend_Auth::getInstance()->clearIdentity();
    }


}

